import { extend } from 'umi-request';
import http from '@/utils/service';
export interface ListItemInter {
  id: number;
  name: string;
  account: string;
  phone: number;
  status: 0 | 1;
}

// 严格按照数据结构来定义
export interface UserListInter {
  page: number;
  totalCount: number;
  // list: Array<ListItemInter>;   有两种定义方式，这两种是一致的
  list: ListItemInter[];
}
export interface UserListQueryInter {
  page: number;
  pageSize: number;
  //   phone: string;
}

const API = {
  userListApi: '/list',
  getLoginUserApi: '/getLoginUser',
  getUserDetail: (id: string) => `/list/detail/${id}`,
};

export interface CreateUserParamsInter {
  name: string;
  phone: string;
  status: 0 | 1;
}

export interface UpdateUserParamsInter extends CreateUserParamsInter {
  id: number;
}

// 放在data里的参数会被放到请求体内，
// 放在params里的参数会被挂在url上  /list?page=1&pageSize=10
export const userListApi = (params: UserListQueryInter) =>
  http.get<UserListInter>(API.userListApi, { xx: params, noeError: true });

export const createUser = (params: CreateUserParamsInter) =>
  http.get<UserListInter>(API.userListApi, { xx: params });

export const updateUser = (params: UpdateUserParamsInter) =>
  http.get<UserListInter>(API.userListApi, { xx: params });

export const getLoginUser = () => http.get<string>(API.getLoginUserApi);

export const getUserDetail = ({ id, data }: { id: string; data: any }) =>
  http.post(API.getUserDetail(id), { data });
